<!DOCTYPE html>
<html lang="en">
<head>
    
    <title>动态日期</title>
    <style>
        #div1{
			width: 600px;
			height: 100px;
			text-align: center;
			line-height: 100px;
			margin: 100px auto;
			border: solid black;
			font-size: 30px;
			}
    </style>
    <script >
		function showTime(){
		    var d = new Date();
		    var year = d.getFullYear();
		    var month = d.getMonth() + 1;//0~11
		    var date = d.getDate();
		
		    var week = d.getDay();//0~6 0是周日
		    week = numOfChinese(week);
		
		    var hour = doubleNum(d.getHours());
		    var min = doubleNum(d.getMinutes());
		    var sec = doubleNum(d.getSeconds());
		
		    var str = year + "年" + month + "月" + date + "日 星期" + week + " " + hour + ":" + min + ":" + sec;
		    return str;
		}
		
		//数字转成中文
		function numOfChinese(num){
		    var arr = ["日","一","二","三","四","五","六"];
		    return arr[num];
		}
		
		function doubleNum(n){
		    if(n < 10){
		        return "0" + n;
		    }else{
		        return n;
		    }
		}
		

	</script>
    <script>
		/*
		  定时器
    格式：var timer = setInterval(函数，毫秒数);
    功能：每隔对应的毫秒数，执行一次传入的函数
    返回值：启动定时器的，系统分配的编号、
    clearInterval(timer); 取消定时器

	格式：var timer = setTimeout(函数,毫秒数);
	功能：使一段代码在指定时间后运行
	clearTimeout(timer);取消定时器
		 */
        setInterval(function(){
            var oTime = document.getElementById("div1");
            oTime.innerHTML = showTime();
        },1000);
    </script>
</head>
<body>
    <div id="div1"></div>
</body>
</html>
